public class Solution7 {
    //467. 环绕字符串中唯一的子字符串
    public int findSubstringInWraproundString(String s) {
        int n = s.length();
        char[] arr = s.toCharArray();
        int[] hash = new int[26];
        int[] dp = new int[n];
        for (int i = 0; i < n; i++) {
            dp[i] = 1;
        }

        for (int i = 1; i < n; i++) {
            if (arr[i-1] + 1 == arr[i] || (arr[i-1] == 'z' && arr[i] == 'a')) {
                dp[i] += dp[i-1];
            }
        }

        //去重操作 相同字符结尾的dp 取大
        int ret = 0;
        for (int i = 0; i < n; i++) {
            hash[arr[i]-'a'] = Math.max(hash[arr[i]-'a'],dp[i]);
        }

        for (int i = 0; i < 26; i++) {
            ret += hash[i];
        }
        return ret;
    }
}
